<template>
  <div class="app-container">
    <el-form
      :model="formData"
      ref="formData"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="100px"
    >
      <el-form-item label="线路组" prop="status">
        <el-input
          v-model="formData.lineGroupName"
          placeholder="请输入"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="线路号码">
        <el-input
          v-model="formData.callerIdNumber"
          placeholder="请输入"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="onClickAdd"
          >新增</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <!-- 表格   -->
    <el-table :loading="loading" :data="tableData">
      <el-table-column label="线路组" align="center" prop="lineGroupName" />
      <el-table-column
        label="线路号码"
        align="center"
        prop="callerIdNumber"
      ></el-table-column>
      <el-table-column label="最大并发量" align="center" prop="param" />
      <el-table-column label="单价（元）" align="center" prop="price" />
      <el-table-column label="机器人单价" align="center" prop="botPrice" />
      <el-table-column label="创建时间" align="center" prop="createTime" />
      <el-table-column label="备注" align="center" prop="content" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button size="mini" @click="onEdit(scope.row)" type="text"
            >编辑</el-button
          >
          <el-button size="mini" @click="onDelete(scope.row)" type="text"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="pagination.pageNum"
      :limit.sync="pagination.pageSize"
      @pagination="getList"
    />

    <addLineGroupDialog
      :id="currentId"
      :addLineGroupDialogShow="addLineGroupDialogShow"
      @onCloseAddLineGroupDialog="onCloseAddLineGroupDialog"
    >
    </addLineGroupDialog>
  </div>
</template>

<script>
import addLineGroupDialog from "./components/addLineGroupDialog.vue";
import {
  lineInfoList,
  deleteLineInfo,
} from "@/api/projectManagement/lineGroupsList.js";
export default {
  name: "lineGroupsList",
  components: { addLineGroupDialog },
  data() {
    return {
      loading: false,
      tableData: [], //表格数据
      showSearch: true, //显示搜索条件
      // 查询参数
      formData: {
        lineGroupName: "", //状态
        callerIdNumber: "", //名称
      },
      statusList: [
        { value: 1, label: "禁用" },
        { value: 0, label: "启用" },
      ], //项目状态
      pagination: {
        pageNum: 1,
        pageSize: 10,
      },
      idList: [],
      total: 0,
      addProjectDialogShow: false,
      advancedSettingDialogShow: false,
      currentId: "",
      multiple: true,
      addLineGroupDialogShow: false,
    };
  },
  async created() {
    this.getList();
  },
  methods: {
    // 列表查询
    async getList() {
      const params = {
        ...this.formData,
        ...this.pagination,
      };

      this.loading = true;
      const { total, rows } = await lineInfoList(params);
      this.total = total;
      this.tableData = rows;
      this.loading = false;
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.pagination.pageNum = 1;
      this.getList();
    },

    /** 重置按钮操作 */
    resetQuery() {
      this.formData = {
        status: 0, //状态
        projectName: "", //名称
      };
      this.handleQuery();
    },
    // 新建
    onClickAdd() {
      this.addLineGroupDialogShow = true;
    },

    // 关闭
    onCloseAddLineGroupDialog() {
      this.addLineGroupDialogShow = false;
      this.currentId = "";
      this.getList();
    },

    // 编辑
    onEdit(row) {
      this.addLineGroupDialogShow = true;
      this.currentId = String(row.id);
    },

    onDelete({ id, lineGroupName }) {
      this.$modal
        .confirm('是否确认删除线路组为"' + lineGroupName + '"的数据项？')
        .then(() => {
          return deleteLineInfo(id);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
  },
};
</script>

<style lang="scss" scoped></style>
